<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use think\Db;

/**
 * 商户管理
 *
 * @icon fa fa-circle-o
 */
class Services extends Backend
{

	/**
	 * Merchant模型对象
	 * @var \app\admin\model\Merchant
	 */
	protected $model = null;

	public function _initialize()
	{
		parent::_initialize();
		$this->model = new \app\admin\model\User;
		// $this->view->assign("isStatusList", $this->model->getIsStatusList());
	}



	/**
	 * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
	 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
	 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
	 */

	/**
	 * 查看
	 */
	public function index()
	{
		//设置过滤方法
		$this->request->filter(['strip_tags', 'trim']);
		if (false === $this->request->isAjax()) {
			return $this->view->fetch();
		}
		//如果发送的来源是Selectpage，则转发到Selectpage
		if ($this->request->request('keyField')) {
			return $this->selectpage();
		}
		$offset = $this->request->param("offset");
		$limit = $this->request->param("limit");
		$defaultWhere = "is_typs in (3,4,5)";
		$lists = [];
		$total = Db::name("user")->where($defaultWhere)->count();
		if ($total) {
			$lists = Db::name("user")
				->alias("a")
				->where($defaultWhere)->limit((int)$offset, (int) $limit)->order('is_typs', "DESC")->select();
			if ($lists) {
				$group =  Db::name("auth_group")->column("name", "id");
				$admin =  Db::name("admin")->column("username", "id");
				foreach ($lists as $key => $value) {
					$lists[$key]['admins'] = $admin[$value["admin_id"]];
					$lists[$key]['depart'] = $group[$value["group_id"]];
					$lists[$key]['avatar'] = $value['avatar'] ? cdnurl($value['avatar'], true) : letter_avatar($value['nickname']);
				}
			}
		}
		$result = ['total' => $total, 'rows' => $lists];
		return json($result);
	}
}
